import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/providers/user_provider.dart';
import 'package:geomancy/styles/index.dart';
import 'package:geomancy/tools/constant.dart';
import 'package:geomancy/widgets/common_btn.dart';
import 'package:geomancy/widgets/common_header.dart';
import 'package:geomancy/widgets/stroke_text.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

const int YEAR = 1990;
const int MONTH = 05;
const int DAY = 15;
class RegisterBirthdayPage extends StatefulWidget {
  const RegisterBirthdayPage({super.key});

  @override
  State<RegisterBirthdayPage> createState() => _RegisterNicknamePageState();
}

class _RegisterNicknamePageState extends State<RegisterBirthdayPage> {
  String _selectedDate = '$YEAR-${MONTH.toString().padLeft(2, '0')}-${DAY.toString().padLeft(2, '0')}';


  void nextHandle() {
    context.read<UserProvider>().setBirthday = '$_selectedDate 00:00:00';
    context.push('/register_avatar');
  }


  Widget _showPickerDate() {
    DateTime dateTime = DateTime.now();
    return Picker(
      hideHeader: true,
      itemExtent: 80.w,
      backgroundColor: ColorStyle.themeLightColor,
      adapter: DateTimePickerAdapter(
          months: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
          customColumnType: [0,1,2],
          yearSuffix: '年',
          yearEnd: dateTime.year,
          daySuffix: '日',
          value: DateTime(YEAR, MONTH, DAY)
      ),
      textStyle: TextStyle(color: ColorStyle.textColor, fontSize: 36.sp),
      selectedTextStyle: const TextStyle(color: Colors.black),
      selectionOverlay: Container(),
      onSelect: (Picker picker, int i, List<int> value) {
        _selectedDate = picker.adapter.getText().split(' ')[0];
      }
    ).makePicker(ThemeData());
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonHeader.appBar(context: context, showActions: false),
      backgroundColor: ColorStyle.pageDefaultColor,
      resizeToAvoidBottomInset: false,
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Container(
          width: double.infinity,
          padding: EdgeInsets.only(top: 100.w, left: Constant.PAGEPADDING.w, right: Constant.PAGEPADDING.w),
          child: DottedBorder(
            borderType: BorderType.RRect,
            strokeWidth: 5.w,
            radius: Radius.circular(60.w),
            dashPattern: [12.w, 6.w],
            color: ColorStyle.borderColor,
            child: Container(
              width: double.infinity,
              height: 1050.w,
              padding: EdgeInsets.only(top: 110.w, bottom: 60.w),
              decoration: BoxDecoration(
                color: ColorStyle.themeLightColor,
                borderRadius: BorderRadius.all(Radius.circular(55.w)),
              ),
              child: Column(
                children: [
                  StrokeText(txt: '设置出生日期', strokeWidth: 8.sp, fontSize: 60.sp, color: ColorStyle.themeColor, fontFamily: 'fontZKKLT'),
                  SizedBox(height: 30.w),
                  Text('慎重选择，不可更改', style: TextStyle(fontSize: 30.sp, color: ColorStyle.textColor)),
                  Expanded(child: Container(
                      alignment: Alignment.center,
                      child: _showPickerDate()
                  )),
                  CommonBtnWidget(size: Size(510.w, 100.w), txt: '下一步', onTap: nextHandle)
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
